package android.slc.db_backup;

import android.slc.db_backup.entity.BackupDb;
import android.slc.db_backup.thread.BackupThread;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.log.Log;

import java.io.File;
import java.util.Objects;

/**
 * @author slc
 * @date 2024/7/23
 **/
public class DbBackupUtils {

    public static void main(String[] args) throws InterruptedException {
        BackupDb backupDb = new BackupDb();
        backupDb.setEnable(true);
        backupDb.setType("MySQL");
        backupDb.setExecBasePath("");
        backupDb.setIp("localhost");
        backupDb.setPort("3306");
        backupDb.setUsername("root");
        backupDb.setPassword("12345678");
        backupDb.setDb("test");//TODO
        backupDb.setLocation("/Users/jrkj");
        //execAsync(backupDb);
        //Thread.sleep(20000);
    }

    public static boolean execAsync(BackupDb backupDb) {
        if (backupDb.getEnable()) {
            Log.get().info("{}启动时运行..", backupDb.toString());
            BackupThread backupThread = new BackupThread(backupDb);
            ThreadUtil.execAsync(backupThread);
            return true;
        }
        return false;
    }

    public static void execSync(BackupDb backupDb) {
        if (backupDb.getEnable()) {
            Log.get().info("{}启动时运行..", backupDb.toString());
            BackupThread backupThread = new BackupThread(backupDb);
            backupThread.run();
        }
    }
}
